# -*- coding: utf-8 -*-

 ###############################################
 ##                                             ##
 ##   Administración                             ##
 ##                                              ##
 ##   for Basiq Empresa                          ##
 ##                                              ##
 ##   by Críptidos Digitales                     ##
 ##   GPL (c)2008                                ##
  ##                                             ##
    ###############################################


from PyQt4 import QtCore, QtGui

import administracion_ui

from cdWidgets import cdSlideFrame

from compras import igu as igCompras
from pedidos import manejador as manejadorPedidos, igu as igPedidos
from reportes import igu as igReportes
# from servicios import manejador as manejadorServicios, igu as igServicios
# from ventas import manejador as manejadorVentas, igu as igVentas

import ventas

# print (0), "administracion        definitions"




class Forma(QtGui.QFrame):

    @property
    def app(self):
        return self.__app

    @property
    def content(self):
        return self.__content

    @property
    def owner(self):
        return self.__owner

    def __init__(self, *args, **kwds):
        if kwds.has_key('app'):
            self.__app = kwds.pop('app')
        else:
            self.__app = None

        if kwds.has_key('content'):
            self.__content = kwds.pop('content')
        else:
            self.__content = None

        if kwds.has_key('owner'):
            self.__owner = kwds.pop('owner')
        else:
            self.__owner = None

        QtGui.QFrame.__init__(self, *args)

        self.ui = administracion_ui.Ui_Form()
        self.ui.setupUi(self)

        self.ui.title.setText(u"CONTROL DE PROCESOS")
        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(9*self.app.fontZoom)

        self.ui.tabWidget.setFont(font)
        self.ui.tabWidget.clear()

        ## Compras
        self.ui.compras = igCompras.Forma(self, owner=self.owner, app=self.app, eventRouter=self.owner)
        self.ui.compras.ui.outerSplitter.setStyleSheet("QSplitter::handle{background-color:#00FF00;}")
        self.ui.tabWidget.addTab(self.ui.compras, u"&Compras")
        self.connect(self.ui.compras, QtCore.SIGNAL('comprasChanged()'), self.comprasChanged)
        self.connect(self.ui.compras, QtCore.SIGNAL('productosChanged()'), self.productosChanged)

        ## Pedidos
        self.ui.pedidos = igPedidos.Forma(self, owner=self.owner, app=self.app, eventRouter=self.owner)
        self.ui.pedidos.ui.outerSplitter.setStyleSheet("QSplitter::handle{background-color:#FF0000;}")
        self.ui.tabWidget.addTab(self.ui.pedidos, u"&Ordenes de Compra")
        self.connect(self.ui.pedidos, QtCore.SIGNAL('pedidosChanged()'), self.pedidosChanged)
        self.connect(self.ui.pedidos, QtCore.SIGNAL('productosChanged()'), self.productosChanged)

        ## Ventas
        self.ui.ventas = self.app.controller('ventas').Form(self, modo='consulta')
        self.ui.ventas.ui.outerSplitter.setStyleSheet("QSplitter::handle{background-color:#FF0000;}")
        self.ui.tabWidget.addTab(self.ui.ventas, u"&Ventas")

        ## Reportes
        self.ui.reportes = igReportes.Forma(self, owner=self.owner, app=self.app)
        self.ui.reportes.ui.outerSplitter.setStyleSheet("QSplitter::handle{background-color:#FF0000;}")
        self.ui.tabWidget.addTab(self.ui.reportes, u"&Reportes")

        self.connect(self.owner, QtCore.SIGNAL('comprasChangedBroadcast()'), self.comprasChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('cuentasChangedBroadcast()'), self.cuentasChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('pedidosChangedBroadcast()'), self.pedidosChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL("productosChangedBroadcast()"), self.productosChangedBroadcast)
        # self.connect(self.owner, QtCore.SIGNAL("proveedoresChangedBroadcast()"), self.proveedoresChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('serviciosChangedBroadcast()'), self.serviciosChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL("ventasChangedBroadcast()"), self.ventasChangedBroadcast)

        # print self.ui.tabWidget.tabBar().height(), self.ui.tabWidget.tabBar().width()
        # print self.ui.tabWidget.tabBar().minimumSize()
        # self.ui.tabWidget.tabBar().setMinimumSize(QtCore.QSize(self.ui.tabWidget.height()*2, self.ui.tabWidget.width()))
        # print self.ui.tabWidget.tabBar().minimumSize()


    # def clientesChanged(self):
        # self.emit(QtCore.SIGNAL("clientesChanged()"))

    # def clasificacionesChanged(self):
        # self.emit(QtCore.SIGNAL("clasificacionesChanged()"))

    def comprasChanged(self):
        self.emit(QtCore.SIGNAL('comprasChanged()'))

    def comprasChangedBroadcast(self):
        self.emit(QtCore.SIGNAL('comprasChangedBroadcast()'))

    def cuentasChangedBroadcast(self):
        print "administracion.Forma.cuentasChangedBroadcast()"
        self.emit(QtCore.SIGNAL('cuentasChangedBroadcast()'))

    def equiposChanged(self):
        self.emit(QtCore.SIGNAL('equiposChanged()'))

    def pedidosChanged(self):
        self.emit(QtCore.SIGNAL("pedidosChanged()"))

    def pedidosChangedBroadcast(self):
        self.emit(QtCore.SIGNAL('pedidosChangedBroadcast()'))

    def productosChanged(self):
        self.emit(QtCore.SIGNAL('productosChanged()'))

    def productosChangedBroadcast(self):    # print "administracion.Forma.productosChangedBroadcast()"
        self.emit(QtCore.SIGNAL("productosChangedBroadcast()"))

    # def proveedoresChangedBroadcast(self):
        # print "administracion.Forma.proveedoresChangedBroadcast()"
        # self.emit(QtCore.SIGNAL("proveedoresChangedBroadcast()"))

    def serviciosChangedBroadcast(self):
        self.emit(QtCore.SIGNAL('serviciosChangedBroadcast()'))

    def ventasChangedBroadcast(self):       # print "administracion.Forma.ventasChangedBroadcast()"
        self.emit(QtCore.SIGNAL("ventasChangedBroadcast()"))

# print (0), "administracion      end"

